<?php
namespace app\beautiful\model\order;
use app\common\model\CommonModel;

class BuyOrderModel extends CommonModel{
    protected  $name = 'beautiful_buy_order';
    protected  $pk   = 'buy_order_id';
    protected $type=[
        'pay_info' => 'array',
    ];

    public function getPriceAttr($value,$data)
    {
        return round(($data['balance']*100 - $data['vip_balance']*100 - $data['coupon_money']*100 - $data['integral_balance']*100)/100,2);
    }

    public function getDiscountMoneyAttr($value,$data)
    {
        return round(($data['vip_balance']*100 + $data['coupon_money']*100 + $data['integral_balance']*100)/100,2);
    }

    public function getDiscountAttr($value,$data)
    {
        return round((($data['balance']*100 - $data['vip_balance']*100)/($data['balance']*100))*10,2);
    }

    public function getPayTypeMeanAttr($value,$data)
    {
        $type_means=[
            'weixin'=>'微信支付',
            'money'=>'余额支付'
        ];
        return $type_means[$data['pay_type']] ?? '其他支付方式';
    }
}
